package com.ruoyi.tea.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tea.domain.TeaProposal;
import com.ruoyi.tea.service.ITeaProposalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 意见反馈Controller
 * 
 * @author ruoyi
 * @date 2022-07-31
 */
@Controller
@RequestMapping("/tea/proposal")
public class TeaProposalController extends BaseController
{
    private String prefix = "tea/proposal";

    @Autowired
    private ITeaProposalService teaProposalService;

    @RequiresPermissions("tea:proposal:view")
    @GetMapping()
    public String proposal()
    {
        return prefix + "/proposal";
    }

    /**
     * 查询意见反馈列表
     */
    @RequiresPermissions("tea:proposal:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeaProposal teaProposal)
    {
        startPage();
        List<TeaProposal> list = teaProposalService.selectTeaProposalList(teaProposal);
        return getDataTable(list);
    }

    /**
     * 导出意见反馈列表
     */
    @RequiresPermissions("tea:proposal:export")
    @Log(title = "意见反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeaProposal teaProposal)
    {
        List<TeaProposal> list = teaProposalService.selectTeaProposalList(teaProposal);
        ExcelUtil<TeaProposal> util = new ExcelUtil<TeaProposal>(TeaProposal.class);
        return util.exportExcel(list, "意见反馈数据");
    }

    /**
     * 新增意见反馈
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存意见反馈
     */
    @RequiresPermissions("tea:proposal:add")
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeaProposal teaProposal)
    {
        return toAjax(teaProposalService.insertTeaProposal(teaProposal));
    }

    /**
     * 修改意见反馈
     */
    @RequiresPermissions("tea:proposal:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TeaProposal teaProposal = teaProposalService.selectTeaProposalById(id);
        mmap.put("teaProposal", teaProposal);
        return prefix + "/edit";
    }

    /**
     * 修改保存意见反馈
     */
    @RequiresPermissions("tea:proposal:edit")
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeaProposal teaProposal)
    {
        return toAjax(teaProposalService.updateTeaProposal(teaProposal));
    }

    /**
     * 删除意见反馈
     */
    @RequiresPermissions("tea:proposal:remove")
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(teaProposalService.deleteTeaProposalByIds(ids));
    }
}
